package test.orwapkg;

import java.io.File;
import java.io.IOException;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class NIOExample {
	
	public static void main(String args[]){
		Path path = Paths.get("D:\\Development\\eclipseworkspace\\testDir\\file.txt");
		System.out.println(path.getFileName());
		System.out.println(path.getFileSystem());
		System.out.println(path.getParent());
		System.out.println(path.getRoot());
		System.out.println(path.startsWith("D:\\Development"));
		System.out.println(path.normalize());
		try {
			path.toRealPath(LinkOption.NOFOLLOW_LINKS);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Path relPath = Paths.get("orwapkg");
		System.out.println(relPath.toAbsolutePath());
		Path path2 = Paths.get("D:\\Development\\eclipseworkspace\\TrainingProject\\orwapkg");
		System.out.println(relPath.equals(path2));
		System.out.println(path2.equals(relPath.toAbsolutePath()));
		System.out.println(relPath.compareTo(path2));
		System.out.println(path2.compareTo(relPath.toAbsolutePath()));
		if (path2.compareTo(relPath.toAbsolutePath()) == 0) {
			System.out.println("relPath equals path2 when relPath converted to its absoulute");
		}
		
		//processing Files
		System.out.println("####### Playing with files ##############");		
		File file = path.toFile();
		System.out.println(file.canExecute());
		System.out.println(file.canRead());
		System.out.println(Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS));
		System.out.println(Files.isDirectory(path2.getParent(), LinkOption.NOFOLLOW_LINKS));
		try {
			System.out.println(Files.isHidden(path));
			System.out.println(Files.isReadable(path));
			System.out.println(Files.size(path));
			
			Files.copy(path, path2.getParent(), StandardCopyOption.REPLACE_EXISTING);
			System.out.println(Files.exists(path2.getParent().resolve("file.txt"), LinkOption.NOFOLLOW_LINKS));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
	}

}
